package com.xtayfjpk.security;

import java.security.MessageDigest;
import java.security.Provider;
import java.security.Security;

import org.junit.Test;

import com.xtayfjpk.security.utils.SecurityUtils;

public class DigestTest {
	
	@Test
	public void test() throws Exception {
		String myInfo = "我的测试信息";
		MessageDigest digest = MessageDigest.getInstance("MD2");
		digest.update(myInfo.getBytes());
		byte[] result = digest.digest();
		System.out.println("本信息摘要为：" + SecurityUtils.toHexString(result));
		
		MessageDigest md = MessageDigest.getInstance("SHA");
		//myInfo = "slkdjfsd";
		md.update(myInfo.getBytes());
		if(MessageDigest.isEqual(result, md.digest())) {
			System.out.println("信息检查正常");
		} else {
			System.out.println("非法摘要");
		}
	}

	@Test
	public void testProviders() {
		Provider[] providers = Security.getProviders();
		for(Provider provider : providers) {
			provider.list(System.out);
		}
	}
	
}
